// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Code generated by sidekick. DO NOT EDIT.
#![allow(rustdoc::redundant_explicit_links)]
#![allow(rustdoc::broken_intra_doc_links)]

/// Implements a client for the Cloud Vision API.
///
/// # Example
/// ```
/// # tokio_test::block_on(async {
/// # use google_cloud_vision_v1::client::ImageAnnotator;
/// let client = ImageAnnotator::builder().build().await?;
/// // use `client` to make requests to the Cloud Vision API.
/// # gax::client_builder::Result::<()>::Ok(()) });
/// ```
///
/// # Service Description
///
/// Service that performs Google Cloud Vision API detection tasks over client
/// images, such as face, landmark, logo, label, and text detection. The
/// ImageAnnotator service returns detected entities from the images.
///
/// # Configuration
///
/// To configure `ImageAnnotator` use the `with_*` methods in the type returned
/// by [builder()][ImageAnnotator::builder]. The default configuration should
/// work for most applications. Common configuration changes include
///
/// * [with_endpoint()]: by default this client uses the global default endpoint
///   (`https://vision.googleapis.com`). Applications using regional
///   endpoints or running in restricted networks (e.g. a network configured
//    with [Private Google Access with VPC Service Controls]) may want to
///   override this default.
/// * [with_credentials()]: by default this client uses
///   [Application Default Credentials]. Applications using custom
///   authentication may need to override this default.
///
/// [with_endpoint()]: super::builder::image_annotator::ClientBuilder::with_endpoint
/// [with_credentials()]: super::builder::image_annotator::ClientBuilder::credentials
/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
///
/// # Pooling and Cloning
///
/// `ImageAnnotator` holds a connection pool internally, it is advised to
/// create one and the reuse it.  You do not need to wrap `ImageAnnotator` in
/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
/// already uses an `Arc` internally.
#[derive(Clone, Debug)]
pub struct ImageAnnotator {
    inner: std::sync::Arc<dyn super::stub::dynamic::ImageAnnotator>,
}

impl ImageAnnotator {
    /// Returns a builder for [ImageAnnotator].
    ///
    /// ```
    /// # tokio_test::block_on(async {
    /// # use google_cloud_vision_v1::client::ImageAnnotator;
    /// let client = ImageAnnotator::builder().build().await?;
    /// # gax::client_builder::Result::<()>::Ok(()) });
    /// ```
    pub fn builder() -> super::builder::image_annotator::ClientBuilder {
        gax::client_builder::internal::new_builder(super::builder::image_annotator::client::Factory)
    }

    /// Creates a new client from the provided stub.
    ///
    /// The most common case for calling this function is in tests mocking the
    /// client's behavior.
    pub fn from_stub<T>(stub: T) -> Self
    where
        T: super::stub::ImageAnnotator + 'static,
    {
        Self {
            inner: std::sync::Arc::new(stub),
        }
    }

    pub(crate) async fn new(
        config: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<Self> {
        let inner = Self::build_inner(config).await?;
        Ok(Self { inner })
    }

    async fn build_inner(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<std::sync::Arc<dyn super::stub::dynamic::ImageAnnotator>> {
        if gaxi::options::tracing_enabled(&conf) {
            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
        }
        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
    }

    async fn build_transport(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<impl super::stub::ImageAnnotator> {
        super::transport::ImageAnnotator::new(conf).await
    }

    async fn build_with_tracing(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<impl super::stub::ImageAnnotator> {
        Self::build_transport(conf)
            .await
            .map(super::tracing::ImageAnnotator::new)
    }

    /// Run image detection and annotation for a batch of images.
    pub fn batch_annotate_images(&self) -> super::builder::image_annotator::BatchAnnotateImages {
        super::builder::image_annotator::BatchAnnotateImages::new(self.inner.clone())
    }

    /// Service that performs image detection and annotation for a batch of files.
    /// Now only "application/pdf", "image/tiff" and "image/gif" are supported.
    ///
    /// This service will extract at most 5 (customers can specify which 5 in
    /// AnnotateFileRequest.pages) frames (gif) or pages (pdf or tiff) from each
    /// file provided and perform detection and annotation for each image
    /// extracted.
    pub fn batch_annotate_files(&self) -> super::builder::image_annotator::BatchAnnotateFiles {
        super::builder::image_annotator::BatchAnnotateFiles::new(self.inner.clone())
    }

    /// Run asynchronous image detection and annotation for a list of images.
    ///
    /// Progress and results can be retrieved through the
    /// `google.longrunning.Operations` interface.
    /// `Operation.metadata` contains `OperationMetadata` (metadata).
    /// `Operation.response` contains `AsyncBatchAnnotateImagesResponse` (results).
    ///
    /// This service will write image annotation outputs to json files in customer
    /// GCS bucket, each json file containing BatchAnnotateImagesResponse proto.
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn async_batch_annotate_images(
        &self,
    ) -> super::builder::image_annotator::AsyncBatchAnnotateImages {
        super::builder::image_annotator::AsyncBatchAnnotateImages::new(self.inner.clone())
    }

    /// Run asynchronous image detection and annotation for a list of generic
    /// files, such as PDF files, which may contain multiple pages and multiple
    /// images per page. Progress and results can be retrieved through the
    /// `google.longrunning.Operations` interface.
    /// `Operation.metadata` contains `OperationMetadata` (metadata).
    /// `Operation.response` contains `AsyncBatchAnnotateFilesResponse` (results).
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn async_batch_annotate_files(
        &self,
    ) -> super::builder::image_annotator::AsyncBatchAnnotateFiles {
        super::builder::image_annotator::AsyncBatchAnnotateFiles::new(self.inner.clone())
    }

    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
    ///
    /// [google.longrunning.Operations]: longrunning::client::Operations
    pub fn get_operation(&self) -> super::builder::image_annotator::GetOperation {
        super::builder::image_annotator::GetOperation::new(self.inner.clone())
    }
}

/// Implements a client for the Cloud Vision API.
///
/// # Example
/// ```
/// # tokio_test::block_on(async {
/// # use google_cloud_vision_v1::client::ProductSearch;
/// let client = ProductSearch::builder().build().await?;
/// // use `client` to make requests to the Cloud Vision API.
/// # gax::client_builder::Result::<()>::Ok(()) });
/// ```
///
/// # Service Description
///
/// Manages Products and ProductSets of reference images for use in product
/// search. It uses the following resource model:
///
/// - The API has a collection of [ProductSet][google.cloud.vision.v1.ProductSet]
///   resources, named `projects/*/locations/*/productSets/*`, which acts as a way
///   to put different products into groups to limit identification.
///
/// In parallel,
///
/// - The API has a collection of [Product][google.cloud.vision.v1.Product]
///   resources, named
///   `projects/*/locations/*/products/*`
///
/// - Each [Product][google.cloud.vision.v1.Product] has a collection of
///   [ReferenceImage][google.cloud.vision.v1.ReferenceImage] resources, named
///   `projects/*/locations/*/products/*/referenceImages/*`
///
///
/// [google.cloud.vision.v1.Product]: crate::model::Product
/// [google.cloud.vision.v1.ProductSet]: crate::model::ProductSet
/// [google.cloud.vision.v1.ReferenceImage]: crate::model::ReferenceImage
///
/// # Configuration
///
/// To configure `ProductSearch` use the `with_*` methods in the type returned
/// by [builder()][ProductSearch::builder]. The default configuration should
/// work for most applications. Common configuration changes include
///
/// * [with_endpoint()]: by default this client uses the global default endpoint
///   (`https://vision.googleapis.com`). Applications using regional
///   endpoints or running in restricted networks (e.g. a network configured
//    with [Private Google Access with VPC Service Controls]) may want to
///   override this default.
/// * [with_credentials()]: by default this client uses
///   [Application Default Credentials]. Applications using custom
///   authentication may need to override this default.
///
/// [with_endpoint()]: super::builder::product_search::ClientBuilder::with_endpoint
/// [with_credentials()]: super::builder::product_search::ClientBuilder::credentials
/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
///
/// # Pooling and Cloning
///
/// `ProductSearch` holds a connection pool internally, it is advised to
/// create one and the reuse it.  You do not need to wrap `ProductSearch` in
/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
/// already uses an `Arc` internally.
#[derive(Clone, Debug)]
pub struct ProductSearch {
    inner: std::sync::Arc<dyn super::stub::dynamic::ProductSearch>,
}

impl ProductSearch {
    /// Returns a builder for [ProductSearch].
    ///
    /// ```
    /// # tokio_test::block_on(async {
    /// # use google_cloud_vision_v1::client::ProductSearch;
    /// let client = ProductSearch::builder().build().await?;
    /// # gax::client_builder::Result::<()>::Ok(()) });
    /// ```
    pub fn builder() -> super::builder::product_search::ClientBuilder {
        gax::client_builder::internal::new_builder(super::builder::product_search::client::Factory)
    }

    /// Creates a new client from the provided stub.
    ///
    /// The most common case for calling this function is in tests mocking the
    /// client's behavior.
    pub fn from_stub<T>(stub: T) -> Self
    where
        T: super::stub::ProductSearch + 'static,
    {
        Self {
            inner: std::sync::Arc::new(stub),
        }
    }

    pub(crate) async fn new(
        config: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<Self> {
        let inner = Self::build_inner(config).await?;
        Ok(Self { inner })
    }

    async fn build_inner(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<std::sync::Arc<dyn super::stub::dynamic::ProductSearch>> {
        if gaxi::options::tracing_enabled(&conf) {
            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
        }
        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
    }

    async fn build_transport(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<impl super::stub::ProductSearch> {
        super::transport::ProductSearch::new(conf).await
    }

    async fn build_with_tracing(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<impl super::stub::ProductSearch> {
        Self::build_transport(conf)
            .await
            .map(super::tracing::ProductSearch::new)
    }

    /// Creates and returns a new ProductSet resource.
    ///
    /// Possible errors:
    ///
    /// * Returns INVALID_ARGUMENT if display_name is missing, or is longer than
    ///   4096 characters.
    pub fn create_product_set(&self) -> super::builder::product_search::CreateProductSet {
        super::builder::product_search::CreateProductSet::new(self.inner.clone())
    }

    /// Lists ProductSets in an unspecified order.
    ///
    /// Possible errors:
    ///
    /// * Returns INVALID_ARGUMENT if page_size is greater than 100, or less
    ///   than 1.
    pub fn list_product_sets(&self) -> super::builder::product_search::ListProductSets {
        super::builder::product_search::ListProductSets::new(self.inner.clone())
    }

    /// Gets information associated with a ProductSet.
    ///
    /// Possible errors:
    ///
    /// * Returns NOT_FOUND if the ProductSet does not exist.
    pub fn get_product_set(&self) -> super::builder::product_search::GetProductSet {
        super::builder::product_search::GetProductSet::new(self.inner.clone())
    }

    /// Makes changes to a ProductSet resource.
    /// Only display_name can be updated currently.
    ///
    /// Possible errors:
    ///
    /// * Returns NOT_FOUND if the ProductSet does not exist.
    /// * Returns INVALID_ARGUMENT if display_name is present in update_mask but
    ///   missing from the request or longer than 4096 characters.
    pub fn update_product_set(&self) -> super::builder::product_search::UpdateProductSet {
        super::builder::product_search::UpdateProductSet::new(self.inner.clone())
    }

    /// Permanently deletes a ProductSet. Products and ReferenceImages in the
    /// ProductSet are not deleted.
    ///
    /// The actual image files are not deleted from Google Cloud Storage.
    pub fn delete_product_set(&self) -> super::builder::product_search::DeleteProductSet {
        super::builder::product_search::DeleteProductSet::new(self.inner.clone())
    }

    /// Creates and returns a new product resource.
    ///
    /// Possible errors:
    ///
    /// * Returns INVALID_ARGUMENT if display_name is missing or longer than 4096
    ///   characters.
    /// * Returns INVALID_ARGUMENT if description is longer than 4096 characters.
    /// * Returns INVALID_ARGUMENT if product_category is missing or invalid.
    pub fn create_product(&self) -> super::builder::product_search::CreateProduct {
        super::builder::product_search::CreateProduct::new(self.inner.clone())
    }

    /// Lists products in an unspecified order.
    ///
    /// Possible errors:
    ///
    /// * Returns INVALID_ARGUMENT if page_size is greater than 100 or less than 1.
    pub fn list_products(&self) -> super::builder::product_search::ListProducts {
        super::builder::product_search::ListProducts::new(self.inner.clone())
    }

    /// Gets information associated with a Product.
    ///
    /// Possible errors:
    ///
    /// * Returns NOT_FOUND if the Product does not exist.
    pub fn get_product(&self) -> super::builder::product_search::GetProduct {
        super::builder::product_search::GetProduct::new(self.inner.clone())
    }

    /// Makes changes to a Product resource.
    /// Only the `display_name`, `description`, and `labels` fields can be updated
    /// right now.
    ///
    /// If labels are updated, the change will not be reflected in queries until
    /// the next index time.
    ///
    /// Possible errors:
    ///
    /// * Returns NOT_FOUND if the Product does not exist.
    /// * Returns INVALID_ARGUMENT if display_name is present in update_mask but is
    ///   missing from the request or longer than 4096 characters.
    /// * Returns INVALID_ARGUMENT if description is present in update_mask but is
    ///   longer than 4096 characters.
    /// * Returns INVALID_ARGUMENT if product_category is present in update_mask.
    pub fn update_product(&self) -> super::builder::product_search::UpdateProduct {
        super::builder::product_search::UpdateProduct::new(self.inner.clone())
    }

    /// Permanently deletes a product and its reference images.
    ///
    /// Metadata of the product and all its images will be deleted right away, but
    /// search queries against ProductSets containing the product may still work
    /// until all related caches are refreshed.
    pub fn delete_product(&self) -> super::builder::product_search::DeleteProduct {
        super::builder::product_search::DeleteProduct::new(self.inner.clone())
    }

    /// Creates and returns a new ReferenceImage resource.
    ///
    /// The `bounding_poly` field is optional. If `bounding_poly` is not specified,
    /// the system will try to detect regions of interest in the image that are
    /// compatible with the product_category on the parent product. If it is
    /// specified, detection is ALWAYS skipped. The system converts polygons into
    /// non-rotated rectangles.
    ///
    /// Note that the pipeline will resize the image if the image resolution is too
    /// large to process (above 50MP).
    ///
    /// Possible errors:
    ///
    /// * Returns INVALID_ARGUMENT if the image_uri is missing or longer than 4096
    ///   characters.
    /// * Returns INVALID_ARGUMENT if the product does not exist.
    /// * Returns INVALID_ARGUMENT if bounding_poly is not provided, and nothing
    ///   compatible with the parent product's product_category is detected.
    /// * Returns INVALID_ARGUMENT if bounding_poly contains more than 10 polygons.
    pub fn create_reference_image(&self) -> super::builder::product_search::CreateReferenceImage {
        super::builder::product_search::CreateReferenceImage::new(self.inner.clone())
    }

    /// Permanently deletes a reference image.
    ///
    /// The image metadata will be deleted right away, but search queries
    /// against ProductSets containing the image may still work until all related
    /// caches are refreshed.
    ///
    /// The actual image files are not deleted from Google Cloud Storage.
    pub fn delete_reference_image(&self) -> super::builder::product_search::DeleteReferenceImage {
        super::builder::product_search::DeleteReferenceImage::new(self.inner.clone())
    }

    /// Lists reference images.
    ///
    /// Possible errors:
    ///
    /// * Returns NOT_FOUND if the parent product does not exist.
    /// * Returns INVALID_ARGUMENT if the page_size is greater than 100, or less
    ///   than 1.
    pub fn list_reference_images(&self) -> super::builder::product_search::ListReferenceImages {
        super::builder::product_search::ListReferenceImages::new(self.inner.clone())
    }

    /// Gets information associated with a ReferenceImage.
    ///
    /// Possible errors:
    ///
    /// * Returns NOT_FOUND if the specified image does not exist.
    pub fn get_reference_image(&self) -> super::builder::product_search::GetReferenceImage {
        super::builder::product_search::GetReferenceImage::new(self.inner.clone())
    }

    /// Adds a Product to the specified ProductSet. If the Product is already
    /// present, no change is made.
    ///
    /// One Product can be added to at most 100 ProductSets.
    ///
    /// Possible errors:
    ///
    /// * Returns NOT_FOUND if the Product or the ProductSet doesn't exist.
    pub fn add_product_to_product_set(
        &self,
    ) -> super::builder::product_search::AddProductToProductSet {
        super::builder::product_search::AddProductToProductSet::new(self.inner.clone())
    }

    /// Removes a Product from the specified ProductSet.
    pub fn remove_product_from_product_set(
        &self,
    ) -> super::builder::product_search::RemoveProductFromProductSet {
        super::builder::product_search::RemoveProductFromProductSet::new(self.inner.clone())
    }

    /// Lists the Products in a ProductSet, in an unspecified order. If the
    /// ProductSet does not exist, the products field of the response will be
    /// empty.
    ///
    /// Possible errors:
    ///
    /// * Returns INVALID_ARGUMENT if page_size is greater than 100 or less than 1.
    pub fn list_products_in_product_set(
        &self,
    ) -> super::builder::product_search::ListProductsInProductSet {
        super::builder::product_search::ListProductsInProductSet::new(self.inner.clone())
    }

    /// Asynchronous API that imports a list of reference images to specified
    /// product sets based on a list of image information.
    ///
    /// The [google.longrunning.Operation][google.longrunning.Operation] API can be
    /// used to keep track of the progress and results of the request.
    /// `Operation.metadata` contains `BatchOperationMetadata`. (progress)
    /// `Operation.response` contains `ImportProductSetsResponse`. (results)
    ///
    /// The input source of this method is a csv file on Google Cloud Storage.
    /// For the format of the csv file please see
    /// [ImportProductSetsGcsSource.csv_file_uri][google.cloud.vision.v1.ImportProductSetsGcsSource.csv_file_uri].
    ///
    /// [google.cloud.vision.v1.ImportProductSetsGcsSource.csv_file_uri]: crate::model::ImportProductSetsGcsSource::csv_file_uri
    /// [google.longrunning.Operation]: longrunning::model::Operation
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn import_product_sets(&self) -> super::builder::product_search::ImportProductSets {
        super::builder::product_search::ImportProductSets::new(self.inner.clone())
    }

    /// Asynchronous API to delete all Products in a ProductSet or all Products
    /// that are in no ProductSet.
    ///
    /// If a Product is a member of the specified ProductSet in addition to other
    /// ProductSets, the Product will still be deleted.
    ///
    /// It is recommended to not delete the specified ProductSet until after this
    /// operation has completed. It is also recommended to not add any of the
    /// Products involved in the batch delete to a new ProductSet while this
    /// operation is running because those Products may still end up deleted.
    ///
    /// It's not possible to undo the PurgeProducts operation. Therefore, it is
    /// recommended to keep the csv files used in ImportProductSets (if that was
    /// how you originally built the Product Set) before starting PurgeProducts, in
    /// case you need to re-import the data after deletion.
    ///
    /// If the plan is to purge all of the Products from a ProductSet and then
    /// re-use the empty ProductSet to re-import new Products into the empty
    /// ProductSet, you must wait until the PurgeProducts operation has finished
    /// for that ProductSet.
    ///
    /// The [google.longrunning.Operation][google.longrunning.Operation] API can be
    /// used to keep track of the progress and results of the request.
    /// `Operation.metadata` contains `BatchOperationMetadata`. (progress)
    ///
    /// [google.longrunning.Operation]: longrunning::model::Operation
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn purge_products(&self) -> super::builder::product_search::PurgeProducts {
        super::builder::product_search::PurgeProducts::new(self.inner.clone())
    }

    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
    ///
    /// [google.longrunning.Operations]: longrunning::client::Operations
    pub fn get_operation(&self) -> super::builder::product_search::GetOperation {
        super::builder::product_search::GetOperation::new(self.inner.clone())
    }
}
